package com.dhcc.cdc.busi.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.busi.dao.*;
import com.dhcc.cdc.busi.entity.*;
import com.dhcc.cdc.busi.service.ICdcDictionaryService;
import com.dhcc.cdc.busi.service.ICdcLocationService;
import com.dhcc.cdc.busi.service.ICdcOrdexecService;
import com.dhcc.cdc.busi.service.ICdcOrdmastService;
import com.dhcc.cdc.sys.dao.CdcDataMapper;
import com.dhcc.cdc.sys.entity.CdcDataEntity;
import com.dhcc.cdc.sys.service.ICdcDataService;
import com.dhcc.core.framework.base.service.impl.BaseServiceImpl;
import com.dhcc.core.framework.util.CommonUtil;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 医嘱执行记录表数据服务层接口
 * 
 * @ClassName: CdcOrdexecServiceImpl
 * @Description: TODO
 * @author jumper
 * @date 2021-03-15 10:20:07
 */
@Service("cdcOrdexecService")
public class CdcOrdexecServiceImpl extends BaseServiceImpl<CdcOrdexecMapper, CdcOrdexecEntity> implements ICdcOrdexecService {

    @Autowired
    ICdcDictionaryService dictritionSrv;
    @Autowired
    ICdcDataService dataSrv;
    @Autowired
    ICdcOrdmastService ordmastSrv;
    @Autowired
    ICdcLocationService locSrv;
	
	@Autowired
	private CdcEpisodeMapper cdcEpisodeMapper;
	
	@Autowired
	private CdcDictypeMapper cdcDictypeMapper;
	
	@Autowired
    private CdcDictionaryMapper cdcDictionaryMapper;
	
	@Autowired
	private CdcUserMapper cdcUserMapper;
	
	@Autowired
	private CdcDataMapper cdcDataMapper;
	
	@Autowired
	private CdcOrdmastMapper cdcOrdmastMapper;
	
	@Autowired
    private CdcLocationMapper cdcLocationMapper;
    
	@Override
	public List<CdcOrdexecEntity> page(Page<CdcOrdexecEntity> page, Map<String, Object> map) {
		return warpOrdexec(this.baseMapper.page(page, map));
	}
	@Override
	public List<CdcOrdexecEntity> list(Map<String, Object> map) {
		return this.baseMapper.list(map);
	}

    public List<CdcOrdexecEntity> warpOrdexec(List<CdcOrdexecEntity> list) {
        Map<Long, Object> cacheDic = new HashMap<Long, Object>();
        
        for (CdcOrdexecEntity ordexec : list) {
            if (ordexec.getOrderMastId() != null) {
                if (cacheDic.containsKey(ordexec.getOrderMastId())) {
                    ordexec.setOrderMast((CdcOrdmastEntity) cacheDic.get(ordexec.getOrderMastId()));
                } else {
                    CdcOrdmastEntity ordMast = this.ordmastSrv.selectById(ordexec.getOrderMastId());
                    ordexec.setOrderMast(ordMast);
                    cacheDic.put(ordexec.getOrderMastId(), ordMast);
                }
            } else {
                ordexec.setOrderMast(new CdcOrdmastEntity());
            }
            if (ordexec.getBusOrderStatusId() != null) {
                if (cacheDic.containsKey(ordexec.getBusOrderStatusId())) {
                    ordexec.setBusOrderStatus((CdcDictionaryEntity) cacheDic.get(ordexec.getBusOrderStatusId()));
                } else {
                    CdcDictionaryEntity orderStatus = this.dictritionSrv.selectById(ordexec.getBusOrderStatusId());
                    ordexec.setBusOrderStatus(orderStatus);
                    cacheDic.put(ordexec.getBusOrderStatusId(), orderStatus);
                }
            } else {
                ordexec.setBusOrderStatus(new CdcDictionaryEntity());
            }
            if (ordexec.getBusOrderInstrucId() != null) {
                if (cacheDic.containsKey(ordexec.getBusOrderInstrucId())) {
                    ordexec.setBusOrderInstruc((CdcDictionaryEntity) cacheDic.get(ordexec.getBusOrderInstrucId()));
                } else {
                    CdcDictionaryEntity OrderInstruc = this.dictritionSrv.selectById(ordexec.getBusOrderInstrucId());
                    ordexec.setBusOrderInstruc(OrderInstruc);
                    cacheDic.put(ordexec.getBusOrderInstrucId(), OrderInstruc);
                }
            } else {
                ordexec.setBusOrderInstruc(new CdcDictionaryEntity());
            }
            if (ordexec.getBusOrderUnitId() != null) {
                if (cacheDic.containsKey(ordexec.getBusOrderUnitId())) {
                    ordexec.setBusOrderUnit((CdcDictionaryEntity) cacheDic.get(ordexec.getBusOrderUnitId()));
                } else {
                    CdcDictionaryEntity OrderUnit = this.dictritionSrv.selectById(ordexec.getBusOrderUnitId());
                    ordexec.setBusOrderUnit(OrderUnit);
                    cacheDic.put(ordexec.getBusOrderUnitId(), OrderUnit);
                }
            } else {
                ordexec.setBusOrderUnit(new CdcDictionaryEntity());
            }
            if (ordexec.getBusOrderFreqId() != null) {
                if (cacheDic.containsKey(ordexec.getBusOrderFreqId())) {
                    ordexec.setBusOrderFreq((CdcDictionaryEntity) cacheDic.get(ordexec.getBusOrderFreqId()));
                } else {
                    CdcDictionaryEntity OrderFreq = this.dictritionSrv.selectById(ordexec.getBusOrderFreqId());
                    ordexec.setBusOrderFreq(OrderFreq);
                    cacheDic.put(ordexec.getBusOrderFreqId(), OrderFreq);
                }
            } else {
                ordexec.setBusOrderFreq(new CdcDictionaryEntity());
            }
            if (ordexec.getOrderLocId() != null) {
                if (cacheDic.containsKey(ordexec.getOrderLocId())) {
                    ordexec.setOrderLoc((CdcLocationEntity) cacheDic.get(ordexec.getOrderLocId()));
                } else {
                    CdcLocationEntity OrderLoc = this.locSrv.selectById(ordexec.getOrderLocId());
                    ordexec.setOrderLoc(OrderLoc);
                    cacheDic.put(ordexec.getOrderLocId(), OrderLoc);
                }
            } else {
                ordexec.setOrderLoc(new CdcLocationEntity());
            }
            if (ordexec.getRecLocId() != null) {
                if (cacheDic.containsKey(ordexec.getRecLocId())) {
                    ordexec.setRecLoc((CdcLocationEntity) cacheDic.get(ordexec.getRecLocId()));
                } else {
                    CdcLocationEntity RecLoc = this.locSrv.selectById(ordexec.getRecLocId());
                    ordexec.setRecLoc(RecLoc);
                    cacheDic.put(ordexec.getRecLocId(), RecLoc);
                }
            } else {
                ordexec.setRecLoc(new CdcLocationEntity());
            }

            if (ordexec.getDataId() != null) {
                if (cacheDic.containsKey(ordexec.getDataId())) {
                    ordexec.setData((CdcDataEntity) cacheDic.get(ordexec.getDataId()));
                } else {
                    CdcDataEntity data = this.dataSrv.selectById(ordexec.getDataId());
                    ordexec.setData(data);
                    cacheDic.put(ordexec.getDataId(), data);
                }
            } else {
                ordexec.setData(new CdcDataEntity());
            }
        }

        return list;
    }
	@Override
	public String handleXmlData(String dataStr) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		Document doc = null;
        try {
            doc = DocumentHelper.parseText(dataStr); // 将字符串转为XML
            Element rootElt = doc.getRootElement(); // 获取根节点
            Iterator<Element> iter = rootElt.elementIterator("ordexecinfo"); // 获取根节点下的子节点ordexecinfo
            // 遍历ordexecinfo节点
            while (iter.hasNext()) {
                Element orderEle = iter.next();
                String xcode = orderEle.elementTextTrim("xcode"); //索引码
                String episodeid = orderEle.elementTextTrim("episodeid"); //就诊记录
                String ordermastid = orderEle.elementTextTrim("ordermastid"); //医嘱项
                String busorderstatuscode = orderEle.elementTextTrim("busorderstatuscode"); //状态代码
                String busorderstatusdesc = orderEle.elementTextTrim("busorderstatusdesc"); //状态描述
                String orderdatestr = orderEle.elementTextTrim("orderdate"); //开医嘱日期
                String orderlocid = orderEle.elementTextTrim("orderlocid"); //开医嘱科室
                String reclocid = orderEle.elementTextTrim("reclocid"); //接收科室
                String startdatestr = orderEle.elementTextTrim("startdate"); //开始日期
                String enddatestr = orderEle.elementTextTrim("enddate"); //停止日期
                String busorderinstruccode = orderEle.elementTextTrim("busorderinstruccode"); //给药途径
                String busorderinstrucdesc = orderEle.elementTextTrim("busorderinstrucdesc"); //给药途径
                String doseqtystr = orderEle.elementTextTrim("doseqty"); //单次剂量
                String busorderunitcode = orderEle.elementTextTrim("busorderunitcode"); //剂量单位
                String busorderunitdesc = orderEle.elementTextTrim("busorderunitdesc"); //剂量单位
                String busorderfreqcode = orderEle.elementTextTrim("busorderfreqcode"); //频次
                String busorderfreqdesc = orderEle.elementTextTrim("busorderfreqdesc"); //频次
                String busorderprioritycode = orderEle.elementTextTrim("busorderprioritycode"); //医嘱类型代码
                String busorderprioritydesc = orderEle.elementTextTrim("busorderprioritydesc"); //医嘱类型描述
                String isantistr = orderEle.elementTextTrim("isanti"); //是否抗生素
                String updatetimestr = orderEle.elementTextTrim("updatetime"); //更新时间
                String updateuserid = orderEle.elementTextTrim("updateuserid"); //更新人
                String opercode = orderEle.elementTextTrim("opercode"); //操作码
                CdcOrdexecEntity order = new CdcOrdexecEntity();
                order.setXcode(xcode);
                //获取basedataId
    			CdcDataEntity cdcDataEntityBase = new CdcDataEntity();
    			cdcDataEntityBase.setCode("HisBase");
    			cdcDataEntityBase.setIsActive(1);
    			cdcDataEntityBase = cdcDataMapper.selectOne(cdcDataEntityBase);
        		Long basedataId = cdcDataEntityBase.getId();
            	//获取dataid
            	CdcDataEntity cdcDataEntity = new CdcDataEntity();
            	cdcDataEntity.setCode("OrdData");
            	cdcDataEntity.setIsActive(1);
            	cdcDataEntity = cdcDataMapper.selectOne(cdcDataEntity);
        		Long dataId = cdcDataEntity.getId();
                if(CommonUtil.isNotEmpty(updatetimestr)) {
            		Date updatetime = sdf.parse(updatetimestr);
            		order.setUpdateDate(updatetime);
            	}
            	//获取更新人
            	if(CommonUtil.isNotEmpty(updateuserid)) {
            		CdcUserEntity cdcUserEntity = new CdcUserEntity();
            		cdcUserEntity.setXcode(updateuserid);
            		cdcUserEntity.setDataId(basedataId);
            		cdcUserEntity.setIsActive(1);
            		cdcUserEntity = cdcUserMapper.selectOne(cdcUserEntity);
            		//判断人员存在不存在
            		Long updateuser = null;
            		if(CommonUtil.isEmpty(cdcUserEntity)) {//不存在  保存到用户表里面
            			cdcUserEntity = new CdcUserEntity();
            			cdcUserEntity.setXcode(updateuserid);
                		cdcUserEntity.setIsActive(1);
            			cdcUserEntity.setCode("newuser"+updateuserid);
            			cdcUserEntity.setName("newuser"+updateuserid);
                		cdcUserEntity.setDataId(basedataId);
                		//保存用户
                		cdcUserMapper.insert(cdcUserEntity);
                		updateuser = cdcUserEntity.getId();
            		}else {
            			updateuser = cdcUserEntity.getId();
            		}
            		order.setUpdateBy(updateuser);
            	}
            	
                if("1".equals(opercode)) {//保存/修改
                	//获取episodeid
                	CdcEpisodeEntity cdcEpisodeEntity = new CdcEpisodeEntity();
                	cdcEpisodeEntity.setXcode(episodeid);
                	cdcEpisodeEntity=cdcEpisodeMapper.selectOne(cdcEpisodeEntity);//就诊信息没在库中？？？
                	Long epsid = cdcEpisodeEntity.getId();
                	order.setEpisodeId(epsid);
                	//根据医嘱条目id获取longid
                	if(CommonUtil.isNotEmpty(ordermastid)) {
                		//如果没有对应ID就要插入
                		CdcOrdmastEntity cdcOrdmastEntity = new CdcOrdmastEntity();
                		cdcOrdmastEntity.setXcode(ordermastid);
                		cdcOrdmastEntity.setDataId(dataId);
                		cdcOrdmastEntity.setIsActive(1);
                		cdcOrdmastEntity = cdcOrdmastMapper.selectOne(cdcOrdmastEntity);
                		if(CommonUtil.isNotEmpty(cdcOrdmastEntity)) {
                			Long orderid =cdcOrdmastEntity.getId();
                			order.setOrderMastId(orderid);
                		}
                	}
                	//获取orderstatusId
                	if(CommonUtil.isNotEmpty(busorderstatuscode)) {
                		CdcDictypeEntity cdcDictypeEntity = new CdcDictypeEntity();
                    	cdcDictypeEntity.setCode("bus_order_status");
                    	cdcDictypeEntity.setIsActive(1);
                    	cdcDictypeEntity = cdcDictypeMapper.selectOne(cdcDictypeEntity);
                		Long dicorderstatusId = cdcDictypeEntity.getId();
                		//如果没有对应ID就要插入
                		CdcDictionaryEntity cdcDictionaryEntity = new CdcDictionaryEntity();
                		cdcDictionaryEntity.setDictypeId(dicorderstatusId);
                		cdcDictionaryEntity.setCode(busorderstatuscode);
                		cdcDictionaryEntity.setIsActive(1);
                		cdcDictionaryEntity = cdcDictionaryMapper.selectOne(cdcDictionaryEntity);
                		//判断字典存在不存在
                		Long busorderstatusid = null;
                		if(CommonUtil.isEmpty(cdcDictionaryEntity)) {//不存在  保存到字典表里面
                			cdcDictionaryEntity = new CdcDictionaryEntity();
                			cdcDictionaryEntity.setDictypeId(dicorderstatusId);
                			cdcDictionaryEntity.setCode(busorderstatuscode);
                			cdcDictionaryEntity.setDescription(busorderstatusdesc);
                			cdcDictionaryEntity.setIsActive(1);
                    		//保存字典
                			cdcDictionaryMapper.insert(cdcDictionaryEntity);
                			busorderstatusid = cdcDictionaryEntity.getId();
                		}else {
                			busorderstatusid = cdcDictionaryEntity.getId();
                		}
                		order.setBusOrderStatusId(busorderstatusid);
                	}
                	if(CommonUtil.isNotEmpty(orderdatestr)) {
                		Date orderdate = sdf.parse(orderdatestr);
                		order.setOrderDate(orderdate);
                	}
                	if(CommonUtil.isNotEmpty(orderlocid)) {
                		CdcLocationEntity cdcLocationEntity = new CdcLocationEntity();
                		cdcLocationEntity.setXcode(orderlocid);
                		cdcLocationEntity.setDataId(basedataId);
                		cdcLocationEntity.setIsActive(1);
                		cdcLocationEntity = cdcLocationMapper.selectOne(cdcLocationEntity);
                		if(CommonUtil.isNotEmpty(cdcLocationEntity)) {
                			Long orderLocLongId = cdcLocationEntity.getId();
                			order.setOrderLocId(orderLocLongId);
                		}
                	}
                	if(CommonUtil.isNotEmpty(reclocid)) {
                		CdcLocationEntity cdcLocationEntity = new CdcLocationEntity();
                		cdcLocationEntity.setXcode(reclocid);
                		cdcLocationEntity.setDataId(basedataId);
                		cdcLocationEntity.setIsActive(1);
                		cdcLocationEntity = cdcLocationMapper.selectOne(cdcLocationEntity);
                		if(CommonUtil.isNotEmpty(cdcLocationEntity)) {
                			Long recLocLongId = cdcLocationEntity.getId();
                			order.setRecLocId(recLocLongId);
                		}
                	}
                	if(CommonUtil.isNotEmpty(startdatestr)) {
                		Date startdate = sdf.parse(startdatestr);
                		order.setStartDate(startdate);
                	}
                	if(CommonUtil.isNotEmpty(enddatestr)) {
                		Date enddate = sdf.parse(enddatestr);
                		order.setOrderDate(enddate);
                	}
                	//获取orderinstrucId
                	if(CommonUtil.isNotEmpty(busorderinstruccode)) {
                		CdcDictypeEntity cdcDictypeEntity = new CdcDictypeEntity();
                    	cdcDictypeEntity.setCode("bus_order_instruc");
                    	cdcDictypeEntity.setIsActive(1);
                    	cdcDictypeEntity = cdcDictypeMapper.selectOne(cdcDictypeEntity);
                		Long dicorderinstrucId = cdcDictypeEntity.getId();
                		//如果没有对应ID就要插入
                		CdcDictionaryEntity cdcDictionaryEntity = new CdcDictionaryEntity();
                		cdcDictionaryEntity.setDictypeId(dicorderinstrucId);
                		cdcDictionaryEntity.setCode(busorderinstruccode);
                		cdcDictionaryEntity.setIsActive(1);
                		cdcDictionaryEntity = cdcDictionaryMapper.selectOne(cdcDictionaryEntity);
                		//判断字典存在不存在
                		Long busorderinstrucid = null;
                		if(CommonUtil.isEmpty(cdcDictionaryEntity)) {//不存在  保存到字典表里面
                			cdcDictionaryEntity = new CdcDictionaryEntity();
                			cdcDictionaryEntity.setDictypeId(dicorderinstrucId);
                			cdcDictionaryEntity.setCode(busorderinstruccode);
                			cdcDictionaryEntity.setDescription(busorderinstrucdesc);
                			cdcDictionaryEntity.setIsActive(1);
                    		//保存字典
                			cdcDictionaryMapper.insert(cdcDictionaryEntity);
                			busorderinstrucid = cdcDictionaryEntity.getId();
                		}else {
                			busorderinstrucid = cdcDictionaryEntity.getId();
                		}
                		order.setBusOrderInstrucId(busorderinstrucid);
                	}
                	
                	if(CommonUtil.isNotEmpty(doseqtystr)) {
                		Float doseqty = Float.valueOf(doseqtystr);
                		order.setDoseQty(doseqty);
                	}
                	//orderpriorityid
                	if(CommonUtil.isNotEmpty(busorderprioritycode)) {
                		CdcDictypeEntity cdcDictypeEntity = new CdcDictypeEntity();
                    	cdcDictypeEntity.setCode("bus_order_priority");
                    	cdcDictypeEntity.setIsActive(1);
                    	cdcDictypeEntity = cdcDictypeMapper.selectOne(cdcDictypeEntity);
                		Long dicorderpriorityId = cdcDictypeEntity.getId();
                		//如果没有对应ID就要插入
                		CdcDictionaryEntity cdcDictionaryEntity = new CdcDictionaryEntity();
                		cdcDictionaryEntity.setDictypeId(dicorderpriorityId);
                		cdcDictionaryEntity.setCode(busorderprioritycode);
                		cdcDictionaryEntity.setIsActive(1);
                		cdcDictionaryEntity = cdcDictionaryMapper.selectOne(cdcDictionaryEntity);
                		//判断字典存在不存在
                		Long busorderpriorityid = null;
                		if(CommonUtil.isEmpty(cdcDictionaryEntity)) {//不存在  保存到字典表里面
                			cdcDictionaryEntity = new CdcDictionaryEntity();
                			cdcDictionaryEntity.setDictypeId(dicorderpriorityId);
                			cdcDictionaryEntity.setCode(busorderprioritycode);
                			cdcDictionaryEntity.setDescription(busorderprioritydesc);
                			cdcDictionaryEntity.setIsActive(1);
                    		//保存字典
                			cdcDictionaryMapper.insert(cdcDictionaryEntity);
                			busorderpriorityid = cdcDictionaryEntity.getId();
                		}else {
                			busorderpriorityid = cdcDictionaryEntity.getId();
                		}
                		order.setBusOrderPriorityId(busorderpriorityid);
                	}
                	//orderunitid
                	if(CommonUtil.isNotEmpty(busorderunitcode)) {
                		CdcDictypeEntity cdcDictypeEntity = new CdcDictypeEntity();
                    	cdcDictypeEntity.setCode("bus_order_unit");
                    	cdcDictypeEntity.setIsActive(1);
                    	cdcDictypeEntity = cdcDictypeMapper.selectOne(cdcDictypeEntity);
                		Long dicorderunitId = cdcDictypeEntity.getId();
                		//如果没有对应ID就要插入
                		CdcDictionaryEntity cdcDictionaryEntity = new CdcDictionaryEntity();
                		cdcDictionaryEntity.setDictypeId(dicorderunitId);
                		cdcDictionaryEntity.setCode(busorderunitcode);
                		cdcDictionaryEntity.setIsActive(1);
                		cdcDictionaryEntity = cdcDictionaryMapper.selectOne(cdcDictionaryEntity);
                		//判断字典存在不存在
                		Long busorderunitid = null;
                		if(CommonUtil.isEmpty(cdcDictionaryEntity)) {//不存在  保存到字典表里面
                			cdcDictionaryEntity = new CdcDictionaryEntity();
                			cdcDictionaryEntity.setDictypeId(dicorderunitId);
                			cdcDictionaryEntity.setCode(busorderunitcode);
                			cdcDictionaryEntity.setDescription(busorderunitdesc);
                			cdcDictionaryEntity.setIsActive(1);
                    		//保存字典
                			cdcDictionaryMapper.insert(cdcDictionaryEntity);
                			busorderunitid = cdcDictionaryEntity.getId();
                		}else {
                			busorderunitid = cdcDictionaryEntity.getId();
                		}
                		order.setBusOrderUnitId(busorderunitid);
                	}
                	//orderfreqid
                	if(CommonUtil.isNotEmpty(busorderfreqcode)) {
                		CdcDictypeEntity cdcDictypeEntity = new CdcDictypeEntity();
                    	cdcDictypeEntity.setCode("bus_order_freq");
                    	cdcDictypeEntity.setIsActive(1);
                    	cdcDictypeEntity = cdcDictypeMapper.selectOne(cdcDictypeEntity);
                		Long dicorderfreqId = cdcDictypeEntity.getId();
                		//如果没有对应ID就要插入
                		CdcDictionaryEntity cdcDictionaryEntity = new CdcDictionaryEntity();
                		cdcDictionaryEntity.setDictypeId(dicorderfreqId);
                		cdcDictionaryEntity.setCode(busorderfreqcode);
                		cdcDictionaryEntity.setIsActive(1);
                		cdcDictionaryEntity = cdcDictionaryMapper.selectOne(cdcDictionaryEntity);
                		//判断字典存在不存在
                		Long busorderfreqid = null;
                		if(CommonUtil.isEmpty(cdcDictionaryEntity)) {//不存在  保存到字典表里面
                			cdcDictionaryEntity = new CdcDictionaryEntity();
                			cdcDictionaryEntity.setDictypeId(dicorderfreqId);
                			cdcDictionaryEntity.setCode(busorderfreqcode);
                			cdcDictionaryEntity.setDescription(busorderfreqdesc);
                			cdcDictionaryEntity.setIsActive(1);
                    		//保存字典
                			cdcDictionaryMapper.insert(cdcDictionaryEntity);
                			busorderfreqid = cdcDictionaryEntity.getId();
                		}else {
                			busorderfreqid = cdcDictionaryEntity.getId();
                		}
                		order.setBusOrderFreqId(busorderfreqid);
                	}
                	//获取orderpriorityId
                	if(CommonUtil.isNotEmpty(busorderprioritycode)) {
                		CdcDictypeEntity cdcDictypeEntity = new CdcDictypeEntity();
                    	cdcDictypeEntity.setCode("bus_order_priority");
                    	cdcDictypeEntity.setIsActive(1);
                    	cdcDictypeEntity = cdcDictypeMapper.selectOne(cdcDictypeEntity);
                		Long dicorderpriorityId = cdcDictypeEntity.getId();
                		//如果没有对应ID就要插入
                		CdcDictionaryEntity cdcDictionaryEntity = new CdcDictionaryEntity();
                		cdcDictionaryEntity.setDictypeId(dicorderpriorityId);
                		cdcDictionaryEntity.setCode(busorderprioritycode);
                		cdcDictionaryEntity.setIsActive(1);
                		cdcDictionaryEntity = cdcDictionaryMapper.selectOne(cdcDictionaryEntity);
                		//判断字典存在不存在
                		Long busorderpriorityid = null;
                		if(CommonUtil.isEmpty(cdcDictionaryEntity)) {//不存在  保存到字典表里面
                			cdcDictionaryEntity = new CdcDictionaryEntity();
                			cdcDictionaryEntity.setDictypeId(dicorderpriorityId);
                			cdcDictionaryEntity.setCode(busorderstatuscode);
                			cdcDictionaryEntity.setDescription(busorderstatusdesc);
                			cdcDictionaryEntity.setIsActive(1);
                    		//保存字典
                			cdcDictionaryMapper.insert(cdcDictionaryEntity);
                			busorderpriorityid = cdcDictionaryEntity.getId();
                		}else {
                			busorderpriorityid = cdcDictionaryEntity.getId();
                		}
                		order.setBusOrderPriorityId(busorderpriorityid);
                	}
                	if(CommonUtil.isNotEmpty(isantistr)) {
                		Integer isanti = Integer.valueOf(isantistr);
                		//order.setIsAnti(isanti);
                	}
            		order.setDataId(dataId);
                	order.setIsActive(1);
                }else {
                	order.setIsActive(0);
                }
                //先判断是不是有该对象
                Wrapper<CdcOrdexecEntity> wrapper =  new EntityWrapper<CdcOrdexecEntity>();
                wrapper.eq("xcode", order.getXcode());
                wrapper.eq("data_id", dataId);
                int count = this.selectCount(wrapper);
                if(count>0) {
                	this.update(order, wrapper);
                }else {
                	this.insert(order);
                }
            }
        } catch (DocumentException e) {
            e.printStackTrace();
            return "<response><status>0</status><message>"+e.getMessage()+"</message></response>";
        } catch (Exception e) {
            e.printStackTrace();
            return "<response><status>0</status><message>"+e.getMessage()+"</message></response>";
        }
		return "<response><status>1</status><message>ok</message></response>";
	}
    

}